﻿using Cartographer.Extensions;
using System.Collections.Generic;
using System.Xml.Linq;

namespace Cartographer.Tiled
{
	public class TiledTileset
	{
		public int FirstGid { get; set; }
		public string Source { get; set; }
		public string Name { get; set; }
		public int TileWidth { get; set; }
		public int TileHeight { get; set; }
		public int Spacing { get; set; }
		public int Margin { get; set; }
		public int Width { get; set; }
		public int Height { get; set; }

		public List<TileOffset> TileOffsets { get; set; }
		public List<TiledProperty> Properties { get; set; }
		public List<TiledImage> Images { get; set; }
		public List<TiledTerrainType> TerrainTypes { get; set; }

		public TiledTileset()
		{
			TileOffsets = new List<TileOffset>();
			Properties = new List<TiledProperty>();
			Images = new List<TiledImage>();
			TerrainTypes = new List<TiledTerrainType>();
		}

		public TiledTileset(XElement element)
		{
			TileOffsets = new List<TileOffset>();
			Properties = new List<TiledProperty>();
			Images = new List<TiledImage>();
			TerrainTypes = new List<TiledTerrainType>();

			FirstGid = element.GetAttribute<int>("firstgid");
			Name = element.GetAttribute<string>("name");
			TileWidth = element.GetAttribute<int>("tilewidth");
			TileHeight = element.GetAttribute<int>("tilewidth");
			Spacing = element.GetAttribute<int>("spacing");
			Margin = element.GetAttribute<int>("margin");

			var image = element.Element("image");
			Source = image.GetAttribute<string>("source");
			Width = image.GetAttribute<int>("width");
			Height = image.GetAttribute<int>("height");
		}
	}
}